﻿///<reference path="../../../../Scripts/jquery-1.4.1-vsdoc.js"/>

function BibleNavigationPane(id) {
    var thisId = id;
    
    this.Container;
    this.BibleNavigationTreeView;

    this.Container = $("<div>", {
        className: "bibleNavigationPane"
    });

    this.Render = function () {
        this.InitializeBibleNavTree();
    }

    this.InitializeBibleNavTree = function () {
        this.BibleNavigationTreeView = new TreeViewBase("bibleNav", this.Container);
        for (var testamentIndex = 0; testamentIndex < appPointer.BiblePlayer.Testaments.length; testamentIndex++) {
            var testament = appPointer.BiblePlayer.Testaments[testamentIndex];
            var testamentNode = this.BibleNavigationTreeView.AddItem("testament_" + testamentIndex,
                 testament.Title, "folder smallText");

            for (var bookIndex = 0; bookIndex < testament.Books.Keys.length; bookIndex++) {
                var book = testament.Books.Lookup(testament.Books.Keys[bookIndex]);
                var bookNode = testamentNode.AddItem("tv_" + book.Key, book.Title, "file smallText clickable unexpandable",
                "$.history.load(\"" + book.Key + "\")", true);
                appPointer.CommandProcessor.RegisterCommand(book.Key, function (hash) {
                    appPointer.MainPaneController.ShowBook(hash);                    
                });

                book.EachChapter(function (chapterIndex) {
                    bookNode.AddItem("tv_" + this.Key, this.Title, "file smallText clickable",
                        "$.history.load(\"" + this.Key + "\")");
                    appPointer.CommandProcessor.RegisterCommand(this.Key, function (hash) {
                        appPointer.MainPaneController.ShowBookChapter(hash);
                    });
                });



            }
        }
        this.BibleNavigationTreeView.Render();
    }
}